package com.tiger.web.controller.communal;

import com.tiger.common.annotation.Log;
import com.tiger.common.core.controller.BaseController;
import com.tiger.common.core.domain.AjaxResult;
import com.tiger.common.core.page.TableDataInfo;
import com.tiger.common.enums.BusinessType;
import com.tiger.common.utils.DateUtils;
import com.tiger.communal.domain.HydropowerAlter;
import com.tiger.communal.service.IHydropowerAlterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 水电历史记录Controller
 *
 * @author standard
 * @date 2022-10-14
 */
@Api(tags = "水电历史记录")
@RestController
@RequestMapping("/system/hydropowerAlter")
public class HydropowerAlterController extends BaseController {
    @Autowired
    private IHydropowerAlterService hydropowerAlterService;

    /**
     * 查询水电历史记录列表
     */
    @ApiOperation(value = "查询水电历史记录列表")
    //@PreAuthorize("@ss.hasPermi('system:alter:list')")
    @GetMapping("/list")
    public TableDataInfo list(HydropowerAlter hydropowerAlter) {
        startPage();
        List<HydropowerAlter> list = hydropowerAlterService.selectHydropowerAlterList(hydropowerAlter);
        return getDataTable(list);
    }


    /**
     * 获取水电历史记录详细信息
     */
    @ApiOperation(value = "获取水电历史记录列详细信息")
    //@PreAuthorize("@ss.hasPermi('system:alter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(hydropowerAlterService.selectHydropowerAlterById(id));
    }

    /**
     * 新增水电历史记录
     */
    @ApiOperation(value = "抄表")
    //@PreAuthorize("@ss.hasPermi('system:alter:add')")
//    @Log(title = "水电历史记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody HydropowerAlter hydropowerAlter) {
        hydropowerAlter.setCreatedAt(DateUtils.getNowDate());
        return toAjax(hydropowerAlterService.insertHydropowerAlter(hydropowerAlter));
    }

    /**
     * 修改水电历史记录
     */
    @ApiOperation(value = "填写支出")
    //@PreAuthorize("@ss.hasPermi('system:alter:edit')")
//    @Log(title = "水电历史记录", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody HydropowerAlter hydropowerAlter) {
        return toAjax(hydropowerAlterService.updateHydropowerAlter(hydropowerAlter));
    }

    /**
     * 删除水电历史记录
     */
    @ApiOperation(value = "删除水电历史记录")
    //@PreAuthorize("@ss.hasPermi('system:alter:remove')")
//    @Log(title = "水电历史记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(hydropowerAlterService.deleteHydropowerAlterByIds(ids));
    }
}
